
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/15/2012 09:43:48
-- Generated from EDMX file: C:\Users\toshiba\Desktop\code\vlusm\Project\VLUSM_Project\VLUSM_DataAccess\DonViHanhChinh.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [VLUSM];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Cap1Cap2]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DVHCCap2] DROP CONSTRAINT [FK_Cap1Cap2];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[DVHCCap1]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DVHCCap1];
GO
IF OBJECT_ID(N'[dbo].[DVHCCap2]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DVHCCap2];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'DVHCCap1'
CREATE TABLE [dbo].[DVHCCap1] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(max)  NOT NULL,
    [MaDonVi] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'DVHCCap2'
CREATE TABLE [dbo].[DVHCCap2] (
    [ID] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(max)  NOT NULL,
    [MaDonVi] nvarchar(max)  NOT NULL,
    [Cap1ID] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [ID] in table 'DVHCCap1'
ALTER TABLE [dbo].[DVHCCap1]
ADD CONSTRAINT [PK_DVHCCap1]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- Creating primary key on [ID] in table 'DVHCCap2'
ALTER TABLE [dbo].[DVHCCap2]
ADD CONSTRAINT [PK_DVHCCap2]
    PRIMARY KEY CLUSTERED ([ID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Cap1ID] in table 'DVHCCap2'
ALTER TABLE [dbo].[DVHCCap2]
ADD CONSTRAINT [FK_Cap1Cap2]
    FOREIGN KEY ([Cap1ID])
    REFERENCES [dbo].[DVHCCap1]
        ([ID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Cap1Cap2'
CREATE INDEX [IX_FK_Cap1Cap2]
ON [dbo].[DVHCCap2]
    ([Cap1ID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------